<template>
  <view class="item-box" v-if="!data">
    <u-skeleton
      title
      :rows="3"
      avatar
      :avatar-size="125"
      avatar-shape="square"
      rowsWidth="100%"
      rowsHeight="14px"
    ></u-skeleton>
  </view>
  <view class="item-box" v-else>
    <view class="top-image">
      <image mode="widthFix" :src="goodsPic"></image>
    </view>
    <view class="bottom-title">
      <view class="title multi-line">{{ data?.goods_name || "-" }}</view>
      <view class="price"><text>￥</text>{{ setPrice(data?.goods_old_price) || 0 }}</view>
    </view>
  </view>
</template>
<script lang="ts" setup>
import { computed, onMounted, watchEffect, ref } from "vue";
import { setImage, filterGame } from "@/util/filter-img";
import type { IFilterImg } from '@/util/filter-img';
const props = defineProps<{
  data?: any;
  mode?: any;
  hotId?: any;
  bonusTemp?: any;
}>();
const goodsPic = ref("");
const loadGoodsPic = async () => {
  if (props.data.verify_account && props.data.verify_account !== 3) {
    const data:IFilterImg = filterGame(props.data.game_id, 1,0);
    await setImage(
      props.data?.goods_pic + "?draw=no",
      (src: string) => {
        goodsPic.value = src;
      },
      data
    );
  }else{
    goodsPic.value = props.data.goods_pic + "?draw=no";
  }
};
const goodsPicComputed = computed(async () => {
  await loadGoodsPic();
  return goodsPic.value;
});
watchEffect(async () => {
  await loadGoodsPic();
});

const setPrice = (price: any) =>{
  try{
    if(price){
      return Number(price).toFixed(0);
    }else{
      return 0;
    }
  }catch(e){
    return 0;
  }
}
</script>

<style lang="scss" scoped>
.multi-line {
  width: 200px; /* 设置容器宽度 */
  display: -webkit-box; /* 使用弹性盒子布局 */
  -webkit-box-orient: vertical; /* 垂直排列 */
  -webkit-line-clamp: 2; /* 限制显示的行数 */
  overflow: hidden; /* 隐藏超出部分 */
  text-overflow: ellipsis; /* 显示省略号 */
}
.item-box {
  width: 100%;
  margin-bottom: 10px;
  .top-image {
    width: 100%;
    max-height: 200px;
    min-height: 100px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    overflow: hidden; /* 确保图像不会溢出容器 */
    image {
      width: 100%;
      object-fit: cover; /* 确保图像按比例填充容器 */
    }
  }
  .bottom-title {
    padding: 10rpx;
    padding-bottom: 20rpx;
    background-color: #fff;
    border-bottom-left-radius: 20rpx;
    border-bottom-right-radius: 20rpx;
    .title {
      font-size: 24rpx;
      width: 100%;
      color: #333333;
      line-height: 35rpx;
      // font-weight: 700;
    }
    .price {
      color: #fe4644;
      margin-top: 20rpx;
      font-size: 32rpx;
      text {
        font-size: 24rpx;
      }
    }
  }
}
</style>
